import React from "react";
import { Route, Switch, Redirect } from "react-router-dom";

import { adminRoutes } from "./routes/index";
import Frame from "./components/Frame/Index";

import { isLogined } from "./utils/auth";

import "./App.css";

function App() {
  return isLogined() ? (
    <Frame>
      <Switch>
        {adminRoutes.map((route) => (
          <Route
            key={route.path}
            {...route}
            render={(routeProps) => <route.component {...routeProps} />}
          />
        ))}
        <Redirect from="/admin" to={adminRoutes[0].path} />
        <Redirect to="/404" />
      </Switch>
    </Frame>
  ) : (
    <Redirect to="/login" />
  );
}

export default App;
